<!DOCTYPE html>
<html>
<head>
	<title>计时器</title>
</head>
<script type="text/javascript">
window.onload = function(){
/*
new Date() 获取当前时间
计时器：
var timer = setInterval(function(){
	//需要执行的
},毫秒)
注：1000毫秒 == 1秒//毫秒必须设置
如果不加控制，一直运行下去
clearInterval(time)//因特否
 */
var ka = document.getElementsByTagName("button")[0];
var je = document.getElementsByTagName("button")[1];
var result = document.getElementById("result");
ka.onclick = function(){
 timer = setInterval(function(){
var sj = new Date();
var year = sj.getFullYear();
var month = sj.getMonth()+1;
var date = sj.getDate();
var day = sj.getDay();
var hour = sj.getHours();
var minute = sj.getMinutes();
var second = sj.getSeconds();

result.innerHTML = year+"年"+two(month)+"月"+two(date)+"日"+two(day)+"周"+two(hour)+"时"+two(minute)+"分"+two(second)+"秒";
},1000)
}
function getWeek(wk){
	var arr = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
	return arr[wk];
}
function two(n){
	return n<10?"0"+n:n;
	//if (n<10) {return "0"+n}else{return n};
}

je.onclick = function(){
	clearInterval(timer);
}



}
</script>
<body>
<div id="result"></div>
<button>开始</button>
<button>结束</button>
</body>
</html>